# -*- coding:utf-8 -*-
"""
Created on 01.05.2010

@author: Пользователь
"""

from django.core.management.base import NoArgsCommand
from berlin.metadata.models import AttributeType, PersonType, GroupType, EventType

class Command(NoArgsCommand):
    
    def handle_noargs(self, **options):
        '''
        Deploy base attribute types in database (if not exists)
        '''
        self._deploy_attr_types()
        self._deploy_person_types()
        self._deploy_group_types()
        self._deploy_event_types()
        
    def _deploy_attr_types(self):
        AttributeType.objects.get_or_create(name='integer', defaultValue='0') 
        AttributeType.objects.get_or_create(name='float', defaultValue='0.0')
        AttributeType.objects.get_or_create(name='string', defaultValue='')
        AttributeType.objects.get_or_create(name='boolean', defaultValue='True')
        AttributeType.objects.get_or_create(name='datetime', defaultValue='01.01.1970 00:00')
        # AttributeType.objects.get_or_create(name='person_reference')
        # AttributeType.objects.get_or_create(name='group_reference')
        # AttributeType.objects.get_or_create(name='event_reference')
        
    def _deploy_person_types(self):
        basePerson, p_exists = PersonType.objects.get_or_create(name=u'Персона')
        PersonType.objects.get_or_create(name=u'Студент', defaults = {'parent' : basePerson})
        PersonType.objects.get_or_create(name=u'Сотрудник', defaults = {'parent' : basePerson})
    
    def _deploy_group_types(self):
        baseGroup, g_exists = GroupType.objects.get_or_create(name=u'Группа')
        GroupType.objects.get_or_create(name=u'Группа студентов', defaults = {'parent' : baseGroup})
        empGroup, e_exists = GroupType.objects.get_or_create(name=u'Группа сотрудников', defaults = {'parent' : baseGroup})
        GroupType.objects.get_or_create(name=u'Кафедра', defaults = {'parent' : empGroup})
        GroupType.objects.get_or_create(name=u'Факультет', defaults = {'parent' : empGroup})
    
    def _deploy_event_types(self):
        baseEvent, e_exists = EventType.objects.get_or_create(name=u'Событие')
        lesson, l_exists = EventType.objects.get_or_create(name=u'Занятие', defaults = {'parent' : baseEvent})
        EventType.objects.get_or_create(name=u'Лекция', defaults = {'parent' : lesson})
        EventType.objects.get_or_create(name=u'Практика', defaults = {'parent' : lesson})
        cpoint, c_exists = EventType.objects.get_or_create(name=u'Контрольная точка', defaults = {'parent' : baseEvent})
        EventType.objects.get_or_create(name=u'Защита курсового проекта', defaults = {'parent' : cpoint})
        EventType.objects.get_or_create(name=u'Зачет', defaults = {'parent' : cpoint})
        EventType.objects.get_or_create(name=u'Экзамен', defaults = {'parent' : cpoint})
    